import copy
import os

from db_exporter.core.connection import Connection
from db_exporter.core.db_struct_info import DBStructInfo
from db_exporter.core.exporter import CSVExport


if __name__ == '__main__':
    conn = Connection(uri="mysql://mysql:mypassword@172.31.1.1:3311/information_schema?charset=utf8",
                      conn_id="testdb")

    db_struct = DBStructInfo(conn)
    db_struct.parse_table_conf()
    table_split_record_dict = db_struct.get_table_split_record_dict()

    export_dir = "./data/"
    if db_struct.conn.conn_id is not None:
        export_dir = os.path.join(export_dir, db_struct.conn.conn_id)

    exporter = CSVExport(export_dir=export_dir, header=True)
    exporter.export_split_records(table_split_record_dict)

    print("export finish. dir: %s" % export_dir)
